package gui;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;


public class StartingMenu extends javax.swing.JPanel {
    
    //StartingMenu startingMenu;
    BufferedImage image;   // holds image for panel background
    int w, h;              // holds dimensions for panel

    /** Creates new panel StartingMenu */
    public StartingMenu() {
        // read the image file and set the custom panel dimensions based on
        // image dimensions.
        try {
            image = ImageIO.read(new File("chips2.JPG"));  // holds image
            w = image.getWidth();                         // holds image width
            h = image.getHeight();                        // holds image height
            // throw exception and exit if file problems
        } catch (IOException ioe) {
            System.out.println(ioe);
            System.exit(0);
        }

       // initComponents();
        initComponents();
        
        
    }
    
    // Generic method to get preferred size
    public Dimension getPreferredSize() {
        return new Dimension(w, h);
    }

    // override of paintComponent to use image
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.drawImage(image, 0, 0, this);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
//    private void initComponents() {
//
//        
//    	jComboBox1 = new javax.swing.JComboBox();
//        FAQButton = new javax.swing.JButton();
//        QuitButton = new javax.swing.JButton();
//        TitleLabel = new javax.swing.JLabel();
//        SelectGameButton = new javax.swing.JButton();
//     
//        
//        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SINGLE PLAYER GAME", "3 PLAYER GAME",
//        		"4 PLAYER GAME", "5 PLAYER GAME", "6 PLAYER GAME" }));
//      
//        FAQButton.setText("    FAQ    ");
//
//        QuitButton.setText("    QUIT   ");
//
//        TitleLabel.setFont(new java.awt.Font("DejaVu Sans Mono", 3, 24)); // NOI18N
//        TitleLabel.setText("Wits and Wagers");
//
//        SelectGameButton.setText("      SELECT GAME      ");
//        
//        
//        //setOpaque(true);
//        
//        
//        GroupLayout layout = new GroupLayout(this);
//        setLayout(layout);
//        layout.setHorizontalGroup(
//            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//            .addGroup(layout.createSequentialGroup()
//                .addGap(277, 277, 277)
//                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
//                   .addComponent(QuitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//                	.addComponent(jComboBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//                    .addComponent(FAQButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//                  //  .addComponent(QuickGameButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//                    .addComponent(SelectGameButton, javax.swing.GroupLayout.DEFAULT_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
//                .addContainerGap(289, Short.MAX_VALUE))
//            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
//                .addContainerGap(230, Short.MAX_VALUE)
//                .addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
//                .addGap(172, 172, 172))
//        );
//        layout.setVerticalGroup(
//            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//            .addGroup(layout.createSequentialGroup()
//                .addGap(26, 26, 26)
//                .addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
//                .addGap(93, 93, 93)
//                //.addComponent(QuickGameButton)
//                .addComponent(jComboBox1)
//                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
//                .addComponent(SelectGameButton)
//                .addGap(9, 9, 9)
//                .addComponent(FAQButton)
//                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
//                .addComponent(QuitButton)
//                .addContainerGap(158, Short.MAX_VALUE))
//        );
//        
//        
//        
//        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//           // 	JComboBox jComboBox1 = (JComboBox) evt.getSource(); 
//                if (jComboBox1.getSelectedIndex() == 0)
//                	MenuCycling.num_Players = 1;
//                else if (jComboBox1.getSelectedIndex() == 1)
//                	MenuCycling.num_Players = 3;
//                else if (jComboBox1.getSelectedIndex() == 2)
//                	MenuCycling.num_Players = 4;
//                else if (jComboBox1.getSelectedIndex() == 3)
//                	MenuCycling.num_Players = 5;
//                else if (jComboBox1.getSelectedIndex() == 4)
//                	MenuCycling.num_Players = 6;
//                StartGameActionPerformed(evt);
//            	
//            }
//        });
// 		
//        
//    }// </editor-fold>//GEN-END:initComponents
    
     private void initComponents() {

        
    	jComboBox1 = new javax.swing.JComboBox();
        FAQButton = new javax.swing.JButton();
        QuitButton = new javax.swing.JButton();
        TitleLabel = new javax.swing.JLabel();
        SelectGameButton = new javax.swing.JButton();
     
        
        
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SINGLE PLAYER GAME", "3 PLAYER GAME",
        		"4 PLAYER GAME", "5 PLAYER GAME", "6 PLAYER GAME" }));
        
        SelectGameButton.setText("      SELECT GAME      ");
      
        FAQButton.setText("    FAQ    ");

        QuitButton.setText("    QUIT   ");

        TitleLabel.setFont(new java.awt.Font("DejaVu Sans Mono", 3, 24)); // NOI18N
        TitleLabel.setText("Wits and Wagers");

        
        jComboBox1.setBackground(Color.BLACK);
        SelectGameButton.setBackground(Color.BLACK);
        FAQButton.setBackground(Color.BLACK);
        QuitButton.setBackground(Color.BLACK);
        
        jComboBox1.setForeground(Color.WHITE);
        SelectGameButton.setForeground(Color.WHITE);
        FAQButton.setForeground(Color.WHITE);
        QuitButton.setForeground(Color.WHITE);
               

      
           
        
        GroupLayout layout = new GroupLayout(this);
        setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(66, 66, 66)
                //.addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                //.addGap(93, 93, 93)
                .addComponent(jComboBox1,GroupLayout.DEFAULT_SIZE,150, GroupLayout.PREFERRED_SIZE)
               // .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGap(46, 46, 46)
                .addComponent(SelectGameButton,GroupLayout.DEFAULT_SIZE,150, GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(FAQButton,GroupLayout.DEFAULT_SIZE,150, GroupLayout.PREFERRED_SIZE)
               // .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGap(46, 46, 46)
                .addComponent(QuitButton,GroupLayout.DEFAULT_SIZE,150, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(58, Short.MAX_VALUE))
        );
        
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(630, 630, 630)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                   .addComponent(QuitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  // .addComponent(jComboBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.DEFAULT_SIZE,40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FAQButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  //  .addComponent(QuickGameButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(SelectGameButton, javax.swing.GroupLayout.DEFAULT_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(289, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(230, Short.MAX_VALUE)
                //.addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                //.addGap(172, 172, 172))
       ) );
        
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
           // 	JComboBox jComboBox1 = (JComboBox) evt.getSource(); 
                if (jComboBox1.getSelectedIndex() == 0)
                	//Single Player currently set to 4 players with 3 dummy players
                	// to avoid out of bounds on OddsCalc.  Logic could be changed to not
                	// calculate odds[2] if single player logic needs it
                	//MenuCycling.num_Players = 1;
                	MenuCycling.num_Players = 4;
                else if (jComboBox1.getSelectedIndex() == 1)
                	MenuCycling.num_Players = 3;
                else if (jComboBox1.getSelectedIndex() == 2)
                	MenuCycling.num_Players = 4;
                else if (jComboBox1.getSelectedIndex() == 3)
                	MenuCycling.num_Players = 5;
                else if (jComboBox1.getSelectedIndex() == 4)
                	MenuCycling.num_Players = 6;
                
                StartGameActionPerformed(evt);
            	
            }
        });
        
        SelectGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectGameButtonActionPerformed(evt);
            }
        });
        
        FAQButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FAQButtonActionPerformed(evt);
            }
        });
        
        QuitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                QuitButtonActionPerformed(evt);
                System.exit(0);
            }
        });
 		
        
    }// </editor-fold>//GEN-END:initComponents
     
     private void StartGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_QuickGameButtonActionPerformed
                  
 		MenuCycling.startGame();

     }//GEN-LAST:event_QuickGameButtonActionPerformed
    

    private void SelectGameButtonActionPerformed(java.awt.event.ActionEvent evt) {
        
		MenuCycling.displaySelectLobbyScreen();
		
    }//GEN-LAST:event_QuickGameButtonActionPerformed
    
    //Pop up FAQ page in browser
    private void FAQButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_QuickGameButtonActionPerformed
    	try {
            //Set your page url in this string. For eg, I m using URL for Google Search engine
            String url = "http://homepages.uwp.edu/dalby001/faq.html";
            java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
          }
          catch (java.io.IOException e) {
              System.out.println(e.getMessage());
          }
   
        
	
    }//GEN-LAST:event_QuickGameButtonActionPerformed

    private void QuitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_QuickGameButtonActionPerformed
        
    	
    }//GEN-LAST:event_QuickGameButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton FAQButton;
    private javax.swing.JButton QuitButton;
    private javax.swing.JButton SelectGameButton;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JComboBox jComboBox1;
  

    // End of variables declaration//GEN-END:variables
}

